#include<iostream>
using namespace std;
#include<pthread.h>
#include<stdio.h>

int g_t = 10000;

void* thread_start(void* arg){
    //修改全局变量
    while(g_t > 0){
        printf("I am %p, i got value is %d\n", pthread_self(), g_t);
        g_t--;
    }
}
int main(){
    //创建两个线程
    pthread_t tid[2];
    for(int i = 0; i < 2; i++){
        int ret = pthread_create(&tid[i], NULL, thread_start, NULL);
        if(ret < 0){
            perror("pthread_create");
            return 0;
        }
    }
    //主线程进行线程等待
    for(int i = 0; i < 2; ++i){
        pthread_join(tid[i], NULL);
    }
    return 0;
}
